/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * panelCrearEmpleado.java
 *
 * Created on Apr 8, 2011, 7:09:06 PM
 */
package frontera.interfaz.panel;

import control.SIRHApp;
import control.comparaciones.ComparacionContenencia;
import control.comportamiento.EscucharBusqueda;
import control.filtros.FiltroCargosEstado;
import entidad.Cargo;
import entidad.Empleado;
import entidad.Falla;
import frontera.interfaz.panel.herramientas.PanelHerramientasBuscar;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Calendar;
import javax.swing.JOptionPane;

/**
 *
 * @author tuareg
 */
public class PanelCrearEmpleado extends javax.swing.JPanel implements EscucharBusqueda<Cargo> {

    /** Creates new form panelCrearEmpleado */
    public PanelCrearEmpleado() {
        initComponents();
        inicializarVariables();

        actualizarSalario();
    }

    PanelCrearEmpleado(String nombre, String cedula, String profesion, Cargo cargoAsociado) {
        initComponents();
        inicializarVariables();
        this.empleadoTemporal.setCargoAsociado(cargoAsociado);
        fieldCargo.setText(cargoAsociado.getNombre());
        fieldNombre.setText(nombre);
        fieldCedula.setText(cedula);
        fieldProfesion.setText(profesion);
        vieneDeCandidatos = true;
    }

    private void inicializarVariables() {
        Calendar cal = Calendar.getInstance();        
        empleadoTemporal = new Empleado("", "", 0, "", "", "", 0, null, "", cal);
    }


    private void verificarFechaCreacion() {
        Calendar cal = Calendar.getInstance();
        ArrayList<Falla> arFallas =new ArrayList<Falla>();
        if (cal.get(Calendar.DATE) > 15) {
            for (int i = 0; i < cal.get(Calendar.DATE) - 16; i++) {
                Falla falla = new Falla(i + 16, empleadoTemporal.getCedula());
                arFallas.add(falla);
                falla.setEmpAsociado(empleadoTemporal);
                //System.out.println(i);
            }
        } else {
            for (int i = 0; i < cal.get(Calendar.DATE) - 1; i++) {
                Falla falla = new Falla(i + 16, empleadoTemporal.getCedula());
                arFallas.add(falla);
            }
        }
        empleadoTemporal.setFallas(arFallas);
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        fieldNombre = new javax.swing.JTextField();
        labelNombre = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        fieldProfesion = new javax.swing.JTextField();
        labelProfesion = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        fieldTelefono = new javax.swing.JTextField();
        labelTelefono = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        labelDireccion = new javax.swing.JLabel();
        fieldDireccion = new javax.swing.JTextField();
        jPanel9 = new javax.swing.JPanel();
        fieldCedula = new javax.swing.JTextField();
        labelCedula = new javax.swing.JLabel();
        titulo = new javax.swing.JLabel();
        iconoAgregar = new javax.swing.JLabel();
        guardarB = new javax.swing.JButton();
        cancelarB = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel12 = new javax.swing.JPanel();
        jPanel17 = new javax.swing.JPanel();
        labelEstado = new javax.swing.JLabel();
        boxEstado = new javax.swing.JComboBox();
        jPanel18 = new javax.swing.JPanel();
        labelPorcentaje = new javax.swing.JLabel();
        fieldPorcentaje = new javax.swing.JFormattedTextField();
        jLabel11 = new javax.swing.JLabel();
        jPanel10 = new javax.swing.JPanel();
        jPanel14 = new javax.swing.JPanel();
        labelEPS = new javax.swing.JLabel();
        fieldEPS = new javax.swing.JTextField();
        jPanel16 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        labelValor = new javax.swing.JLabel();
        jPanel11 = new javax.swing.JPanel();
        jPanel15 = new javax.swing.JPanel();
        buscarCargoB = new javax.swing.JButton();
        labelCargo = new javax.swing.JLabel();
        fieldCargo = new javax.swing.JTextField();
        jPanel13 = new javax.swing.JPanel();
        labelEmpleado = new javax.swing.JLabel();
        labelResultado = new javax.swing.JLabel();

        addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                formPropertyChange(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos Básicos"));
        jPanel1.setLayout(new java.awt.GridLayout(0, 1));

        labelNombre.setText("Nombres y Apellidos");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelNombre)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(fieldNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelNombre)
                    .addComponent(fieldNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel1.add(jPanel3);

        jPanel4.setLayout(new java.awt.GridLayout(1, 0));

        labelProfesion.setText("Profesion");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelProfesion)
                .addGap(18, 18, 18)
                .addComponent(fieldProfesion, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fieldProfesion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelProfesion))
                .addContainerGap())
        );

        jPanel4.add(jPanel6);

        labelTelefono.setText("Teléfono");

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelTelefono)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(fieldTelefono, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fieldTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelTelefono))
                .addContainerGap())
        );

        jPanel4.add(jPanel7);

        jPanel1.add(jPanel4);

        jPanel5.setLayout(new java.awt.GridLayout(1, 0));

        labelDireccion.setText("Dirección");

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelDireccion)
                .addGap(18, 18, 18)
                .addComponent(fieldDireccion, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelDireccion)
                    .addComponent(fieldDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel5.add(jPanel8);

        labelCedula.setText("Cédula");

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelCedula)
                .addGap(19, 19, 19)
                .addComponent(fieldCedula, javax.swing.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fieldCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelCedula))
                .addContainerGap())
        );

        jPanel5.add(jPanel9);

        jPanel1.add(jPanel5);

        titulo.setFont(new java.awt.Font("Dialog", 1, 32));
        titulo.setText("Creando Nuevo Empleado");

        iconoAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/frontera/recursos/AddEmpleado.png"))); // NOI18N

        guardarB.setIcon(new javax.swing.ImageIcon(getClass().getResource("/frontera/recursos/Save.png"))); // NOI18N
        guardarB.setText("Guardar");
        guardarB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardarBActionPerformed(evt);
            }
        });

        cancelarB.setIcon(new javax.swing.ImageIcon(getClass().getResource("/frontera/recursos/Cancelar.png"))); // NOI18N
        cancelarB.setText("Cancelar");
        cancelarB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarBActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Laboral"));
        jPanel2.setLayout(new java.awt.GridLayout(0, 1));

        jPanel12.setLayout(new java.awt.GridLayout(1, 0));

        labelEstado.setText("Estado");

        boxEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Activo" }));

        javax.swing.GroupLayout jPanel17Layout = new javax.swing.GroupLayout(jPanel17);
        jPanel17.setLayout(jPanel17Layout);
        jPanel17Layout.setHorizontalGroup(
            jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel17Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(boxEstado, 0, 205, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel17Layout.setVerticalGroup(
            jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel17Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelEstado)
                    .addComponent(boxEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        jPanel12.add(jPanel17);

        labelPorcentaje.setText("Porcentaje Salarial");

        fieldPorcentaje.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                fieldPorcentajeKeyReleased(evt);
            }
        });

        jLabel11.setText("%");

        javax.swing.GroupLayout jPanel18Layout = new javax.swing.GroupLayout(jPanel18);
        jPanel18.setLayout(jPanel18Layout);
        jPanel18Layout.setHorizontalGroup(
            jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel18Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelPorcentaje)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(fieldPorcentaje, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel11)
                .addContainerGap())
        );
        jPanel18Layout.setVerticalGroup(
            jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel18Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fieldPorcentaje, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelPorcentaje)
                    .addComponent(jLabel11))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jPanel12.add(jPanel18);

        jPanel2.add(jPanel12);

        jPanel10.setLayout(new java.awt.GridLayout(1, 0));

        labelEPS.setText("EPS");

        javax.swing.GroupLayout jPanel14Layout = new javax.swing.GroupLayout(jPanel14);
        jPanel14.setLayout(jPanel14Layout);
        jPanel14Layout.setHorizontalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelEPS, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(fieldEPS, javax.swing.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel14Layout.setVerticalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelEPS)
                    .addComponent(fieldEPS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel10.add(jPanel14);

        jLabel1.setText("Salario");

        labelValor.setText("Valor");

        javax.swing.GroupLayout jPanel16Layout = new javax.swing.GroupLayout(jPanel16);
        jPanel16.setLayout(jPanel16Layout);
        jPanel16Layout.setHorizontalGroup(
            jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel16Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(65, 65, 65)
                .addComponent(labelValor, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(90, Short.MAX_VALUE))
        );
        jPanel16Layout.setVerticalGroup(
            jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel16Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(labelValor))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jPanel10.add(jPanel16);

        jPanel2.add(jPanel10);

        jPanel11.setLayout(new java.awt.GridLayout(1, 0));

        buscarCargoB.setIcon(new javax.swing.ImageIcon(getClass().getResource("/frontera/recursos/search.png"))); // NOI18N
        buscarCargoB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarCargoBActionPerformed(evt);
            }
        });

        labelCargo.setText("Cargo");

        fieldCargo.setEditable(false);
        fieldCargo.setText("Sin Asignar");

        javax.swing.GroupLayout jPanel15Layout = new javax.swing.GroupLayout(jPanel15);
        jPanel15.setLayout(jPanel15Layout);
        jPanel15Layout.setHorizontalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel15Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelCargo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(fieldCargo, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buscarCargoB, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel15Layout.setVerticalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel15Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(buscarCargoB, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(labelCargo)
                        .addComponent(fieldCargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jPanel11.add(jPanel15);

        javax.swing.GroupLayout jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout.setHorizontalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 289, Short.MAX_VALUE)
        );
        jPanel13Layout.setVerticalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 53, Short.MAX_VALUE)
        );

        jPanel11.add(jPanel13);

        jPanel2.add(jPanel11);

        labelEmpleado.setText(" ");

        labelResultado.setText(" ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 589, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 589, Short.MAX_VALUE)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(iconoAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(labelEmpleado, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(titulo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                .addComponent(labelResultado, javax.swing.GroupLayout.PREFERRED_SIZE, 562, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addContainerGap(27, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(guardarB)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cancelarB)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(iconoAgregar)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(39, 39, 39)
                        .addComponent(titulo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelEmpleado, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(1, 1, 1)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(labelResultado, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(guardarB)
                    .addComponent(cancelarB))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void cancelarBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarBActionPerformed
        if (vieneDeCandidatos)
            JOptionPane.showMessageDialog(SIRHApp.getInstance().getVentanaPrincipal(), "Debe crear este empleado pues ha sido seleccionado \n"
                    + "después de ser candidato.", "Nuevo Empleado", JOptionPane.INFORMATION_MESSAGE);
        else
            SIRHApp.getInstance().getVentanaPrincipal().setPanelPersonalEmpleado(SIRHApp.getInstance().getVentanaPrincipal().getPanelEmpleados());
        ((PanelHerramientasBuscar<Empleado>) SIRHApp.getInstance().getFactoryInterfaz().getPanelEmpleados().getPanelHerramientas()).inicializarBusqueda();
        SIRHApp.getInstance().getVentanaPrincipal().getPanelEmpleados().actualizarLista(SIRHApp.getInstance().getSistema().getEmpleados());
    }//GEN-LAST:event_cancelarBActionPerformed

    private void actualizarEmpleadoTemporal() {
        empleadoTemporal.setNombre(fieldNombre.getText());
        empleadoTemporal.setCedula(fieldCedula.getText());
        empleadoTemporal.setTelefono(Long.parseLong(fieldTelefono.getText()));
        empleadoTemporal.setDireccion(fieldDireccion.getText());
        empleadoTemporal.setProfesion(fieldProfesion.getText());
        empleadoTemporal.setEstado((String) boxEstado.getSelectedItem());
        empleadoTemporal.setPorcentajeSalarioBas(Float.parseFloat(fieldPorcentaje.getText()));
        empleadoTemporal.setEPS(fieldEPS.getText());

    }

    private void guardarBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarBActionPerformed
        Calendar cal = Calendar.getInstance();
        actualizarEmpleadoTemporal();
        verificarFechaCreacion();    
        //System.out.println("asd");
        for(Falla fa:empleadoTemporal.getFallas()){
            //System.out.println(fa.getCedula());
            //System.out.println("-");
        }
        
        String resultadoOperacion = SIRHApp.getInstance().getAdmEmpleados().crearEmpleado(fieldNombre.getText(),
                fieldCedula.getText(),
                fieldTelefono.getText(),
                fieldDireccion.getText(),
                fieldProfesion.getText(),
                (String) boxEstado.getSelectedItem(),
                fieldPorcentaje.getText(),
                empleadoTemporal.getCargoAsociado(),
                fieldEPS.getText(),
                cal,
                empleadoTemporal.getFallas());
        if (resultadoOperacion.equals("")) {
            actualizarEmpleadoTemporal();
            
            
            SIRHApp.getInstance().getVentanaPrincipal().setPanelPersonalEmpleado(SIRHApp.getInstance().getVentanaPrincipal().getPanelEmpleados());
            ((PanelHerramientasBuscar<Empleado>) SIRHApp.getInstance().getFactoryInterfaz().getPanelEmpleados().getPanelHerramientas()).inicializarBusqueda();
            SIRHApp.getInstance().getVentanaPrincipal().getPanelEmpleados().actualizarLista(SIRHApp.getInstance().getSistema().getEmpleados());

        } else {
            labelResultado.setText(resultadoOperacion);
        }
    }//GEN-LAST:event_guardarBActionPerformed

    private void buscarCargoBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarCargoBActionPerformed
        ArrayList<Cargo> cargos = SIRHApp.getInstance().getAdmCargos().buscar(new FiltroCargosEstado(), new ComparacionContenencia(), "En Proceso");
        SIRHApp.getInstance().getVentanaPrincipal().setPanelPersonalEmpleado(SIRHApp.getInstance().getFactoryInterfaz().getPanelBusquedaCargo(this, this, this.getParent(),cargos));

    }//GEN-LAST:event_buscarCargoBActionPerformed

    private void formPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_formPropertyChange
        
    }//GEN-LAST:event_formPropertyChange

    private void fieldPorcentajeKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_fieldPorcentajeKeyReleased
        actualizarSalario();
    }//GEN-LAST:event_fieldPorcentajeKeyReleased

    private void actualizarSalario(){
        if(empleadoTemporal.getCargoAsociado()!=null&&fieldPorcentaje.getText().equals("")!=true && (fieldPorcentaje.getText().matches("\\d*\\.\\d*") || fieldPorcentaje.getText().matches("\\d*"))){
            float porcentaje = Float.parseFloat(fieldPorcentaje.getText());
            float salario = porcentaje/100 * Float.parseFloat(empleadoTemporal.getCargoAsociado().getSalarioBásico());
            NumberFormat formatter = new DecimalFormat("#0.00");
            labelValor.setText(formatter.format(salario));
        }
        else{
            labelValor.setText(Float.toString(0));            
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox boxEstado;
    private javax.swing.JButton buscarCargoB;
    private javax.swing.JButton cancelarB;
    private javax.swing.JTextField fieldCargo;
    private javax.swing.JTextField fieldCedula;
    private javax.swing.JTextField fieldDireccion;
    private javax.swing.JTextField fieldEPS;
    private javax.swing.JTextField fieldNombre;
    private javax.swing.JFormattedTextField fieldPorcentaje;
    private javax.swing.JTextField fieldProfesion;
    private javax.swing.JTextField fieldTelefono;
    private javax.swing.JButton guardarB;
    private javax.swing.JLabel iconoAgregar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel16;
    private javax.swing.JPanel jPanel17;
    private javax.swing.JPanel jPanel18;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JLabel labelCargo;
    private javax.swing.JLabel labelCedula;
    private javax.swing.JLabel labelDireccion;
    private javax.swing.JLabel labelEPS;
    private javax.swing.JLabel labelEmpleado;
    private javax.swing.JLabel labelEstado;
    private javax.swing.JLabel labelNombre;
    private javax.swing.JLabel labelPorcentaje;
    private javax.swing.JLabel labelProfesion;
    private javax.swing.JLabel labelResultado;
    private javax.swing.JLabel labelTelefono;
    private javax.swing.JLabel labelValor;
    private javax.swing.JLabel titulo;
    // End of variables declaration//GEN-END:variables
    private Empleado empleadoTemporal;
    private boolean vieneDeCandidatos = false;

    public void procesarResultadoBusqueda(Cargo resultado) {
        empleadoTemporal.setCargoAsociado(resultado);
        
        fieldCargo.setText(resultado.getNombre());
        actualizarSalario();
        SIRHApp.getInstance().getVentanaPrincipal().setPanelPersonalEmpleado(this);
    }
}
